package org.record.mood.config;

import org.record.mood.web.intercept.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description:
 * @author: sunyw
 * @time: 2020-04-16 16:43
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/admin/**").
                excludePathPatterns("/admin/login").excludePathPatterns("/admin/index").excludePathPatterns("/static/**")
        .excludePathPatterns("/admin/registerpage").excludePathPatterns("/admin/register");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/admin/index").setViewName("/admin/loginpage");
        registry.addViewController("/admin/registerpage").setViewName("/admin/register");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/*").addResourceLocations("classpath:/static/admin/*");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
